package com.yeyks.controller.admin;

import com.yeyks.annotation.AdminAppLog;
import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.appcommon.dto.room.AppRoomCalendarJipDTO;
import com.yeyks.common.appcommon.param.calendar.UpdateRoomCalendarJipParam;
import com.yeyks.common.appcommon.param.room.GetRoomCalendarParam;
import com.yeyks.common.appcommon.result.CommonResult;
import com.yeyks.common.exception.OftenFiledException;
import com.yeyks.common.exception.ServiceException;
import com.yeyks.common.utils.apputil.bean.MyBeanUtils;
import com.yeyks.commonReference.service.calendar.RoomCalendarJipInfoService;
import com.yeyks.controller.BaseController;
import com.yeyks.hotel.dal.domain.RoomCalendarJipInfo;
import com.yeyks.hotel.param.UpdateRoomCalendarBatchParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

import static com.yeyks.common.constants.SysLogMsg.ROOM_UPDATE_JIP_CALENDAR;

/**
 * @author Administrator
 */
@Api(tags = "AppRoomCalendarController_房间房态的操作接口", description = "房间房态的操作接口，【更新VIP房间房态】" +
        "【查询优享VIP房间房态】(1.7.0)")
@RestController
@RequestMapping("/admin/calendar")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AppRoomCalendarController extends BaseController {

    /**
     * 小V房态
     */
    private final RoomCalendarJipInfoService roomCalendarJipInfoService;



    @ApiOperation("获取优享客房房态信息")
    @PostMapping("/get/min/vip")
    public CommonResult<List<AppRoomCalendarJipDTO>> getRoomCalendar(@Valid GetRoomCalendarParam param) {

        validToken(param.getToken(), param.getVersion(), param.getPlatform());

        List<RoomCalendarJipInfo> roomCalendarJipInfoList = roomCalendarJipInfoService.selectVIPRoomCalendar(param.getRoomId());

        return CommonResult.success(MyBeanUtils.convertArrayList(roomCalendarJipInfoList, AppRoomCalendarJipDTO.class));
    }

    @AdminAppLog(value = ROOM_UPDATE_JIP_CALENDAR)
    @ApiOperation("更新房态信息")
    @PostMapping("/update/min/vip")
    public CommonResult updateRoomCalendar(@Valid UpdateRoomCalendarJipParam param) {

        validToken(param.getToken(), param.getVersion(), param.getPlatform());

        UpdateRoomCalendarBatchParam params = new UpdateRoomCalendarBatchParam();
        params.setHotelId(param.getHotelId());
        params.setRoomId(param.getRoomId());
        params.setCalendarData(param.getCalendarData());
        try {
            AjaxResponseBody body = roomCalendarJipInfoService.updateRoomCalendarBatch(params);
            if(body.getCode() == 0){
                return CommonResult.success(body.getMsg());
            }
            return CommonResult.failed(body.getMsg());
        }catch (ServiceException ex){
            throw new OftenFiledException(ex.getMessage());
        }
    }
}
